<?php
/*
 * Theme Admin
 * 
 * created by: PG2287
 */
class Larch_admin {
	function __construct() {
		
	}
	public function create_admin_page_options(){ ?>
		<div class="wrap">
			<h1>Larch Theme Options</h1>
			<div class="container">
				<div class="row">
					<nav class="navbar navbar-default">
						<ul class="menu nav nav-tabs">
							<li class="active"><a href="#general" data-toggle="tab">General</a></li>
							<li><a href="#header" data-toggle="tab">Header</a></li>
							<li><a href="#content" data-toggle="tab">Content</a></li>
							<li><a href="#footer" data-toggle="tab">Footer</a></li>
						</ul>
					</nav>
					<form method="post" action ="options.php">
						<?php settings_errors(); ?>
						<section class="tab-content">
							<div class="tab-pane active fade in" id="general">
								<?php
									settings_fields('larch_general_option');
									do_settings_sections('larch_general_option');
								?>
							</div>
							<div class="tab-pane fade" id="header">
								<?php
									settings_fields('larch_header_option');
									do_settings_sections('larch_header_option');
								?>
							</div>
							<div class="tab-pane fade" id="content">
								
							</div>
							<div class="tab-pane fade" id="footer">
								<?php
									settings_fields('larch_footer_option');
									do_settings_sections('larch_footer_option');
								?>
							</div>
						</section>
						<?php submit_button('Save'); ?>
					</form>
				</div>
			</div>
			
		</div>
	<?php }
	function create_setting_section($args){
		foreach($args as $a){
			add_settings_section($a['id'], $a['title'],  Larch_admin::section_callback(), $a['page']);
		}
	}
	function create_setting_field($args){
		foreach($args as $a){
			add_settings_field($a['id'], $a['title'],'create_field', $a['page'], $a['section'],$a['args']);
		}
	}

	function section_callback(){}
	function create_field($cb_args){
		extract($cb_args);
		$larch_settings = get_option($option_name);
		$larch_settings[$id] = (isset($larch_settings[$id]))? esc_attr(stripslashes($larch_settings[$id])):'';
		//$larch_settings[$id] = esc_attr(stripslashes($larch_settings[$id]));
		switch ( $type) {
			case 'checkbox':
				echo "<input id ='$id' name='".$option_name."[$id]' type='$type' value='1' ".checked(1,$larch_settings[$id],false)."><label for='$id'>$desc</label>";
				break;
			case 'text':
				echo "<input id ='$id' name='".$option_name."[$id]' type='$type' value='$larch_settings[$id]'><label for='$id'>$desc</label>";
				break;
			case 'tel':
				echo "<input id ='$id' name='".$option_name."[$id]' type='$type' value='$larch_settings[$id]'><label for='$id'>$desc</label>";
				break;
			case 'email':
				echo "<input id ='$id' name='".$option_name."[$id]' type='$type' value='$larch_settings[$id]'><label for='$id'>$desc</label>";
				break;
			case 'textarea':
				echo "<textarea name='".$option_name."[$id]' id ='$id'>$larch_settings[$id]</textarea>";
				break;
			default:
				break;
		}
	}
	/*********************************************************
	 * 
	 */
	function create_spec_setting_field(){
			add_settings_field('dummy_text', 'Dummy Text','create_spec_field', 'larch_footer_option', 'larch_footer_option',array('dum'));
	}
	
	/*
	 * 
	 *********************************************************/
	function add_admin_options($options = array()){
			if(!empty($options)){
				for($x = 0; $x < sizeof($options); $x++){
					if(false==get_option($options[$x])){add_option($options[$x]);}
				}
			}
	}
	function del_admin_options($options = array()){
			if(!empty($options)){
				for($x = 0; $x < sizeof($options); $x++){
					delete_option($options[$x]);
				}
			}
	}
	function register_admin_settings($settings = array()){
		if(!empty($settings)){
			foreach ( $settings as $s) {
				register_setting($s['option_group'], $s['option']);
			}
		}
	}
}
